import pymysql
def parse_three(json):
    if json:
        db = pymysql.connect(host='localhost',user='root',password='9269790',port=3306)
        cursor = db.cursor()
        cursor.execute('CREATE DATABASE AJAX DEFAULT CHARACTER SET utf8mb4')
        db.close()
        db2 = pymysql.connect('localhost','root',"密码","AJAX",3306)
        cursor2 = db2.cursor()
        cursor2.execute("DROP TABLE IF EXISTS ajax")
        sql1 = """CREATE TABLE'ajax'(
        'car_name’char(20)NOT NULL,
        'id' int(10) NOT NULL AUTO_INCREMENT,
        PRIMARY KRY('id')
        )ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;"""
        cursor2.execute(sql1)
        print("Created table Successfull.")

        for i in json:
            for b in i .get('SeriesList'):
                item_list = b.get('Name')
                item_list2 = b.get("Id")
                print(item_list+":"+str(item_list2))
                sql2 = 'INSERT INTO ajax(car_name,id)VALUER(%s,%s)'
                try:
                    cursor2.execute(sql2,(item_list,item_list2))
                    db2.commit()
                except:
                    db2.rollback()
        db2.close()


def get_one(param):
    pass


if __name__ =='__main__':
    city_list = [{'北京':'110100'}]
    for city in city_list:
        jo = get_one(city.values())
        parse_three(jo)
# 20224.9.30
